﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using DAL.Linq.EntityMapper;

namespace DAL.Linq
{
    public class LinqDMLOAITHUE_Dao : IDMLOAITHUE_Dao
    {

        #region IDao<DMLOAITHUEInfo,int> Members

        /// <summary>
        /// Gets a list of all DMLOAITHUEs.
        /// </summary>
        /// <returns>List of DMLOAITHUEs.</returns>
        public IList<DMLOAITHUE> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a specific DMLOAITHUE.
        /// </summary>
        /// <param name="maLoaiThue">Unique MaLoaiThue identifier.</param>
        /// <returns>DMLOAITHUE.</returns>
        public DMLOAITHUE GetById(int maLoaiThue)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDMLOAITHUE_Dao Members

        public bool DMLoaiThue_Insert(string MaCode, string TenLoaiThue, bool IsUse, int CreateBy)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMLoaiThue_Insert(MaCode, TenLoaiThue, IsUse, CreateBy);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool DMLoaiThue_Update(int MaLoaiThue, string TenLoaiThue, bool IsUse,  int ModifiedBy, DateTime ModifiedOn)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMLoaiThue_Update(MaLoaiThue, TenLoaiThue, IsUse, ModifiedBy,ModifiedOn);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool DMLoaiThue_Delete(int MaLoaiThue)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMLoaiThue_Delete(MaLoaiThue);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public IList<DMLOAITHUE> GetAll_DMLoaiThue()
        {
            List<DMLOAITHUE> lst = null;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    lst = db.sp_DMLoaiThue_GetAll().Select(p => Mapper.ToBusinessObject(p)).ToList();
                }
                catch { }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
            }
            return lst;
        }

        #endregion
    }
}
